package com.flong.modules.service;

import java.sql.SQLException;
import java.util.List;

import com.flong.modules.AppException;
import com.flong.modules.BaseService;
import com.flong.modules.model.oracle.UserTabComments;
import com.flong.modules.utils.DBHelper;
import com.flong.modules.utils.ObjectUtil;
/**
 * @Description	TODO
 * @ClassName	UserTabCommentsService
 * @Date		2017年3月1日 下午3:20:48
 * @Author		liangjilong
 * @Copyright (c) All Right Reserved , 2017.
 */
@SuppressWarnings("all")
public class UserTabCommentsService extends BaseService {
	
	private static String SELECT_USER_TAB_COMMENTS_SQL = "select table_name, table_type, comments from user_tab_comments ";
	/**
	 * @Author		liangjilong
	 * @Date		2017年2月23日 下午2:30:56
	 * @throws Exception 		参数
	 * @return 		List<String> 返回类型
	 */
	public static List<UserTabComments> getUserTabComments() throws Exception {
		conn = DBHelper.getInstance().getConnection(); //链接数据库
		if(ObjectUtil.isNotEmpty(dialect) && "ORACLE".equalsIgnoreCase(dialect)){
			sql = SELECT_USER_TAB_COMMENTS_SQL;//
		}else if(ObjectUtil.isNotEmpty(dialect) && "SQLSERVER".equalsIgnoreCase(dialect)){
			
		}else if(ObjectUtil.isNotEmpty(dialect) && "MYSQL".equalsIgnoreCase(dialect)){
			
		}else{
			throw new AppException(1,"方言配置有误，目前只支持MYSQL和Oracle");
		}
		return retTabList(sql);
	}
	
	/**
	 * @Description 根据表名和列名获取注释
	 * @Author		liangjilong
	 * @Date		2017年3月1日 下午3:22:33
	 * @param tableName
	 * @param columnName
	 * @return
	 * @throws Exception 		参数
	 * @return 		List<UserColComments> 返回类型
	 */
	public static List<UserTabComments> getUserTabCommentsByName(String tableName) throws Exception {
		conn = DBHelper.getInstance().getConnection(); //链接数据库
		if(ObjectUtil.isNotEmpty(dialect) && "ORACLE".equalsIgnoreCase(dialect)){
			sql = SELECT_USER_TAB_COMMENTS_SQL+ " where upper(table_name)=upper('"+tableName+"') ";//
		}else if(ObjectUtil.isNotEmpty(dialect) && "SQLSERVER".equalsIgnoreCase(dialect)){
			
		}else if(ObjectUtil.isNotEmpty(dialect) && "MYSQL".equalsIgnoreCase(dialect)){
			
		}else{
			throw new AppException(1,"方言配置有误，目前只支持MYSQL和Oracle");
		}
		return retTabList(sql);
	}

	private static List<UserTabComments> retTabList(String sql) {
		List<UserTabComments> convertToEntitys = null;
		try {
			psmt = conn.prepareStatement(sql);
			rs = psmt.executeQuery();
			convertToEntitys = DBHelper.convertToEntitys(rs, UserTabComments.class);
		}  catch (Exception e) {
			e.printStackTrace();
		}finally {
			DBHelper.release(conn, psmt, rs);
		}
		return convertToEntitys;
	}
	
	
	public static void main(String[] args) throws Exception{
	 
	}
}
